USE [CustomersSuppliers]
/****** Object:  StoredProcedure [dbo].[Contacts-Insert]    Script Date: [[20120914064949]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120914064949]]
-- Description:	Insert record into table [dbo].[Contacts]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Contacts-Insert]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Contacts-Insert]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Contacts-Insert]
	/*@Contact_RowNumber int =Null OUTPUT , 
	@Contact_ID uniqueidentifier =Null  , 
	@Person_ID uniqueidentifier =Null  , 
	@ContactType_ID uniqueidentifier =Null  , 
	@Contact_Value varchar(max) =Null  , 
	@Contacts_TimeStamp timestamp =Null OUTPUT*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	INSERT  INTO [dbo].[Contacts](/*[Contact_ID], [Person_ID], [ContactType_ID], [Contact_Value]*/)
	VALUES     (/*@Contact_ID, @Person_ID, @ContactType_ID, @Contact_Value*/)

	/*SELECT @Contact_RowNumber = [Contact_RowNumber], @Contacts_TimeStamp = [Contacts_TimeStamp]
    FROM [dbo].[Contacts]
    WHERE  ( [Contact_ID] =@Contact_ID )
	AND  ( [Person_ID] =@Person_ID )
	AND  ( [ContactType_ID] =@ContactType_ID )
	AND  ( [Contact_Value] =@Contact_Value )*/
END
GO
-- =============================================
USE [CustomersSuppliers]
/****** Object:  StoredProcedure [dbo].[Contacts-update]    Script Date: [[20120914064949]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120914064949]]
-- Description:	Update record in table [dbo].[Contacts]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Contacts-update]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Contacts-update]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Contacts-update]
	/*@Contact_RowNumber int =Null OUTPUT , 
	@Contact_ID uniqueidentifier =Null  , 
	@Person_ID uniqueidentifier =Null  , 
	@ContactType_ID uniqueidentifier =Null  , 
	@Contact_Value varchar(max) =Null  , 
	@Contacts_TimeStamp timestamp =Null OUTPUT , 
	@OldTimeStamp timeStamp OUTPUT*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	/*SELECT @OldTimeStamp = [Contacts_TimeStamp]
    FROM [dbo].[Contacts]
    	WHERE ([Contact_ID] = @Contact_ID)

    IF  @OldTimeStamp = @Contacts_TimeStamp
    BEGIN*/
		Update [dbo].[Contacts] SET 
		/*[Contact_ID] =@Contact_ID, 
		[Person_ID] =@Person_ID, 
		[ContactType_ID] =@ContactType_ID, 
		[Contact_Value] =@Contact_Value*/
		/*WHERE ([Contact_ID] = @Contact_ID)*/
	/*END*/

	/*SELECT @Contact_RowNumber = [Contact_RowNumber], @Contacts_TimeStamp = [Contacts_TimeStamp]
    FROM [dbo].[Contacts]
	WHERE ([Contact_ID] = @Contact_ID)*/
END
GO
-- =============================================
USE [CustomersSuppliers]
/****** Object:  StoredProcedure [dbo].[Contacts-Insert-Update]    Script Date: [[20120914064949]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120914064949]]
-- Description:	Insert OR Update record into table [dbo].[Contacts]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Contacts-Insert-Update]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Contacts-Insert-Update]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Contacts-Insert-Update]
	/*@Contact_RowNumber int =Null OUTPUT , 
	@Contact_ID uniqueidentifier =Null  , 
	@Person_ID uniqueidentifier =Null  , 
	@ContactType_ID uniqueidentifier =Null  , 
	@Contact_Value varchar(max) =Null  , 
	@Contacts_TimeStamp timestamp =Null OUTPUT , 
	@Inserted bit OUTPUT , 
	@OldTimeStamp timeStamp OUTPUT*/ 
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;
	IF NOT EXISTS (SELECT * FROM [dbo].[Contacts] 
					/*WHERE ([Contact_ID] = @Contact_ID)*/)
	BEGIN
		
		INSERT  INTO [dbo].[Contacts](/*[Contact_ID], [Person_ID], [ContactType_ID], [Contact_Value]*/)
		VALUES     (/*@Contact_ID, @Person_ID, @ContactType_ID, @Contact_Value*/)

		SET /*@*/Inserted=1
	END
	ELSE
	BEGIN
		
		/*SELECT @OldTimeStamp = [Contacts_TimeStamp]
		FROM [dbo].[Contacts]
    	WHERE ([Contact_ID] = @Contact_ID)

		IF  @OldTimeStamp = @Contacts_TimeStamp
		BEGIN*/
			Update [dbo].[Contacts] SET 
			/*[Contact_ID] =@Contact_ID, 
			[Person_ID] =@Person_ID, 
			[ContactType_ID] =@ContactType_ID, 
			[Contact_Value] =@Contact_Value*/
			/*WHERE ([Contact_ID] = @Contact_ID)*/
		/*END*/
		
		SET /*@*/Inserted=0
	END

	/*SELECT @Contact_RowNumber = [Contact_RowNumber], @Contacts_TimeStamp = [Contacts_TimeStamp]
    FROM [dbo].[Contacts]
	WHERE ([Contact_ID] = @Contact_ID)*/
END
GO
-- =============================================
USE [CustomersSuppliers]
/****** Object:  StoredProcedure [dbo].[Contacts-Delete]    Script Date: [[20120914064949]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120914064949]]
-- Description:	delete records from table [dbo].[Contacts] based on optional Conditions
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Contacts-Delete]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Contacts-Delete]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Contacts-Delete]
	/*@Contact_RowNumber int =null  , 
	@Contact_ID uniqueidentifier =null  , 
	@Person_ID uniqueidentifier =null  , 
	@ContactType_ID uniqueidentifier =null  , 
	@Contact_Value varchar(max) =null  , 
	@Contacts_TimeStamp timestamp =null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	Delete FROM  [dbo].[Contacts]
	WHERE /*( [Contact_RowNumber] = ISNULL(@Contact_RowNumber, [Contact_RowNumber]) )
	AND ( [Contact_ID] = ISNULL(@Contact_ID, [Contact_ID]) )
	AND ( [Person_ID] = ISNULL(@Person_ID, [Person_ID]) )
	AND ( [ContactType_ID] = ISNULL(@ContactType_ID, [ContactType_ID]) )
	AND ( [Contact_Value] like ISNULL(@Contact_Value, [Contact_Value]) )
	AND ( [Contacts_TimeStamp] = ISNULL(@Contacts_TimeStamp, [Contacts_TimeStamp]) )*/
END
GO
-- =============================================
USE [CustomersSuppliers]
/****** Object:  StoredProcedure [dbo].[Contacts-Select]    Script Date: [[20120914064949]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120914064949]]
-- Description:	select records from table [dbo].[Contacts] based on optional Conditions
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Contacts-Select]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Contacts-Select]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Contacts-Select]
	/*@Contact_RowNumber int =null  , 
	@Contact_ID uniqueidentifier =null  , 
	@Person_ID uniqueidentifier =null  , 
	@ContactType_ID uniqueidentifier =null  , 
	@Contact_Value varchar(max) =null  , 
	@Contacts_TimeStamp timestamp =null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	SELECT * FROM  [dbo].[Contacts]
	WHERE /*( [Contact_RowNumber] = ISNULL(@Contact_RowNumber, [Contact_RowNumber]) )
	AND ( [Contact_ID] = ISNULL(@Contact_ID, [Contact_ID]) )
	AND ( [Person_ID] = ISNULL(@Person_ID, [Person_ID]) )
	AND ( [ContactType_ID] = ISNULL(@ContactType_ID, [ContactType_ID]) )
	AND ( [Contact_Value] like ISNULL(@Contact_Value, [Contact_Value]) )
	AND ( [Contacts_TimeStamp] = ISNULL(@Contacts_TimeStamp, [Contacts_TimeStamp]) )*/
END
GO
-- =============================================
